<?
include('header.php');

$query1 = mysql_query("SELECT * FROM `ytsubs` WHERE `active`='0' AND `user`='{$data['id']}'");
$query = mysql_num_rows($query1);
$query2 = mysql_fetch_object($query1);


  $site2 = mysql_query("SELECT * FROM `ytsubs` WHERE (`active` = '0' AND `points` >= `cpc`) AND (`id` NOT IN (SELECT `site_id` FROM `ytsubed` WHERE `user_id`='{$data['id']}') AND `user`!='{$data['id']}') ORDER BY `cpc` DESC LIMIT 0, 5");
  $ext = mysql_num_rows($site2);
?>
<div class="block medium right">
			<div class="top"><?if(isset($data['id'])) {?>	
                  <h1>Earn Coins - Youtube Subscribers</h1>
            </div>
			<div class="content">	
<?
if($query > 0){
if($ext > 0){
?>
<p>Press "Subscribe" on the user, then press "Subscribe" on Youtube's page. After that, press "Confirm".</p>
<script>
var user= "<? echo $data['id'];?>";
function skipuser(str,username) {
document.getElementById("txtHint").style.display='block';
	$("#txtHint").html('<table cellpadding="2" cellspacing="0" width="500" align="center" class="maintable"><tr><td align="center"><font size="3"><b>Skipping '+username+'</b></font></td></tr><tr><td><center><font size=2><b>Skipping... <img src="ajax-loader.gif"></b></font></center></td></tr></table><br>');
	$.ajax({
		type: "GET",
		url: "subscribed.php?step=skip",
		data: "id="+str+"&usr="+user,
		success: function(msg){
			$("#txtHint").html(msg);
		}
	});
	remove(str);
}
function followuser(str,username)
{
document.getElementById("txtHint").style.display='block';
	$("#txtHint").html('<table cellpadding="2" cellspacing="0" width="500" align="center" class="maintable"><tr><td align="center"><font size="3"><b>Did you Subscribe to '+username+'?</b></font></td></tr><tr><td><center><font size=2><b>Verifying... <img src="ajax-loader.gif"></b></font></center></td></tr></table><br>');
	$.ajax({
		type: "GET",
		url: "subscribed.php",
		data: "id="+str+"&usr="+user,
		success: function(msg){
			$("#txtHint").html(msg);
		}
	});
}

function remove(Variable) {
document.getElementById("follow"+Variable).style.display='none';
}
</script>
<center><div id="txtHint" style="display:none;"></div></center>
<div id="getpoints">
<?
  for($j=1; $site = mysql_fetch_object($site2); $j++){
?>	
<div class="follow" id="follow<? echo $site->id;?>"><center><img src="<?echo $site->y_av;?>" border="0" alt="@<? echo $site->y_name;?>" width="48" height="48" class="follower"><br><b>Coins</b>: <? echo $site->cpc;?><br><center><a href="javascript:void(0);" onclick="window.open('<? echo $site->y_link;?>','Youtube','status=0,toolbar=0,width=1000,height=500,resizable=0,menubar=0,location=0,directories=0');" class="followbutton">Subscribe</a>
<a href="javascript:void(0);" onclick="followuser('<? echo $site->id;?>','<? echo $site->y_name;?>');" class="followbutton">Confirm</a>
</center><font style="font-size:0.8em;">[<a href="javascript:void(0);" onclick="skipuser('<? echo $site->id;?>','<? echo $site->y_name;?>');remove('6923');" style="color: #666666;font-size:0.9em;">skip</a>]</font></center></div>
<?}?>
</div>
<br>
<div class='infobox'>Follow the users and refresh page to see the addition of Coins!
<form action='' method='' onsubmit='refreshpage();'>
<input name='refresh' type='submit' value='Refresh'>
</form></div>
<?}else{?>
<br>
<div class="msg">
<div class="error">Sorry, there are no more coins to be earned at the moment. Please try again later.</div>
<div class="info"><a href="buycoins.php"><b>Feel like you need more coins? You can purchase them now!</b></a></div></div>
<?}}else{?>
<div class="msg"><div class="error"><a href="ysubconfig.php">Add your Youtube account first!</a></div></div>
<?}}else{?><script>document.location.href='index.php'</script><?}?>
				</div>
			</div>		
<?include('footer.php');?>